package drds.server.sqlparser.sqlobject.statement.query;

import java.util.ArrayList;
import java.util.List;

import drds.server.sqlparser.sqlobject.AbstractSqlObject;
import drds.server.sqlparser.sqlobject.expression.Expression;
import drds.server.sqlparser.visitor.Visitor;

/**
 * 需要支持group_concat()函数解析
 * 
 * @author 曹正辉<330937205@qq.com>
 * 
 */
public class GroupBy extends AbstractSqlObject {

	private final List<Expression> groupByItemList = new ArrayList<Expression>();
	private Expression filter;

	public GroupBy() {

	}

	public void addGroupByItem(Expression groupByItem) {
		if (groupByItem != null) {
			groupByItem.setParent(this);
			this.groupByItemList.add(groupByItem);
		}
	}

	public List<Expression> getGroupByItemList() {
		return this.groupByItemList;
	}

	public void setFilter(Expression filter) {
		if (filter != null) {
			filter.setParent(this);
		}

		this.filter = filter;
	}

	public Expression getFilter() {
		return this.filter;
	}

	protected void accept0(Visitor visitor) {
		if (visitor.visit(this)) {
			acceptChild(visitor, this.groupByItemList);
			acceptChild(visitor, this.filter);
		}

		visitor.endVisit(this);
	}
}
